import java.util.StringTokenizer;


class P11541_39643 {

	   static String readLn() {
	        String newLine = System.getProperty("line.separator");
	        StringBuilder buffer = new StringBuilder();
	        int car = -1;
	        try {
	            car = System.in.read();
	            while ((car > 0) && (car != newLine.charAt(0))) {
	                buffer.append((char) car);
	                car = System.in.read();
	            }
	            if (car == newLine.charAt(0))
	                System.in.skip(newLine.length() - 1);
	        } catch (java.io.IOException e) {
	            return (null);
	        }
	        if ((car < 0) && (buffer.length() == 0))
	            return (null);
	        return (buffer.toString());
	    }
	
	public static void main(String[] args) {
		int cases = Integer.parseInt(readLn());
		
		for (int k = 0; k < cases; k++) {
			String line = readLn();
			
			StringTokenizer st = new StringTokenizer(line, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", true);
			
			StringBuilder sb = new StringBuilder();
			
			while (st.hasMoreTokens()) {
				String letter  = st.nextToken();
				int i = Integer.parseInt(st.nextToken());
				
				for (int  j = 0; j < i; j++) {
					sb.append(letter);
				}
				
			}
			
			
			System.out.println("Case " + (k + 1) + ": " + sb.toString());
		}
		
	}
	
}
